package com.excel.service;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import com.utils.JsonResult;

/**   
* @Title: ExcelExportService.java 
* @Package com.excel.service 
* @author 孙梦楠 
* @date 2017年11月5日 下午1:22:16 
* @version V1.0.0   
*/
@Service
public class ExcelExportService {
	
	
	public JsonResult<String> exportTemplate(){
		
		
		return new JsonResult<String>(0, null, null);
	}
	
	public JsonResult<String> exportRecordreport() throws FileNotFoundException, IOException{
		
		XSSFWorkbook wb = new XSSFWorkbook();
		SimpleDateFormat smf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
		String fileName = "download";
		XSSFSheet sheet = wb.createSheet(fileName);  //创建table工作薄
		Object[][] datas = {{"用户名", "用户地址", "用户电话","终端出厂编号","终端资产编号","终端类型(只能为数字，具体值在字典查询)",
			"终端设备安装地址","终端通讯地址","终端通讯方式(只能为数字，具体值在字典查询)","终端制造单位(只能为数字，具体值在字典查询)","采集器出厂编号",
			"采集器资产编号","采集器类型(只能为数字，具体值在字典查询)","采集器通信地址","采集器协议(只能为数字，具体值在字典查询)",
			"采集器制造单位(只能为数字，具体值在字典查询)","表出厂编号","表资产编号","表类别(只能为数字，具体值在字典查询)","表通讯地址",
			"表安装地址","表协议(只能为数字，具体值在字典查询)","表制造单位(只能为数字，具体值在字典查询)","表密码","倍率(只能为数字)",
			"密钥类型(只能为数字，具体值在字典查询)","测量点号","测量点序号","端口(只能为数字，具体值在字典查询) ","波特率(只能为数字，具体值在字典查询)",
			"大类(只能为数字，具体值在字典查询)","小类(只能为数字，具体值在字典查询) ","整数位(只能为数字，具体值在字典查询)","小数位(只能为数字，具体值在字典查询)"}};
		XSSFRow row;
		XSSFCell cell;
		for(int i = 0; i < datas.length; i++) {
		    row = sheet.createRow(i);//创建表格行
		    for(int j = 0; j < datas[i].length; j++) {
		        cell = row.createCell(j);//根据表格行创建单元格
		        cell.setCellValue(String.valueOf(datas[i][j]));
		    }
		}
		//创建表格之后设置行高与列宽
		
		    row = sheet.getRow(0);
		    row.setHeightInPoints(70);//设置行高
		wb.write(new FileOutputStream("D:/temp/"+fileName+".xlsx"));
		wb.close();
		
		return new JsonResult<String>(0, null, fileName+".xlsx");
	}
	
	//把所有的档案导出到一张表中
	private Object[][] getdata(){
		
		
		
		
		return null;
	}
}
